import Vue from 'vue'
import Router from 'vue-router'
// import store from '@/store'

Vue.use(Router)

// console.log(store.state.menu)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']    will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if true, the page will no be cached(default is false)
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
  {
    path: 'upload',
    component: resolve => require(['@/views/upload/index'], resolve),
    name: 'upload',
    meta: { title: '上传图片', icon: 'upload', noCache: true }
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: resolve => require(['@/views/redirect/index'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: resolve => require(['@/views/login/index'], resolve),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: resolve => require(['@/views/login/authredirect'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: resolve => require(['@/views/errorPage/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: resolve => require(['@/views/errorPage/401'], resolve),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: 'dashboard',
    meta: { title: '仪表盘', icon: 'dashboard', noCache: true },
    children: [{
      path: 'dashboard',
      component: resolve => require(['@/views/dashboard/index'], resolve),
      name: 'Dashboard',
      meta: { title: '仪表盘', icon: 'dashboard', noCache: true }
    }]
  }
]

export default new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/auth',
    component: Layout,
    redirect: '/auth/index',
    meta: { title: '权限设置', icon: 'auth', noCache: true },
    children: [
      {
        path: 'user_auth',
        name: 'user_auth',
        component: resolve => require(['@/views/auth/index'], resolve),
        meta: { title: '管理员权限', icon: 'user_auth', noCache: true }
      },
      {
        path: 'group',
        component: resolve => require(['@/views/auth/group'], resolve),
        name: 'group',
        meta: { title: '权限管理', icon: 'user_group', noCache: true }
      },
      {
        path: 'log',
        component: resolve => require(['@/views/auth/log'], resolve),
        name: 'log',
        meta: { title: '操作日志', icon: 'user_group', noCache: true }
      },
      {
        path: 'upload',
        component: resolve => require(['@/views/upload/index'], resolve),
        name: 'upload',
        meta: { title: '上传图片', icon: 'user_group', noCache: true }
      }
    ]
  },
  /* {
    path: '/clolmun',
    component: Layout,
    redirect: '/clolmun/index',
    meta: { title: '栏目管理', icon: 'auth', noCache: true },
    children: [
      {
        path: 'clolmun',
        name: 'clolmun',
        component: resolve => require(['@/views/clolmun/index'], resolve),
        meta: { title: '栏目管理', icon: 'user_auth', noCache: true }
      }
    ]
  }, */
  {
    path: '/users',
    component: Layout,
    redirect: '/clolmun/users',
    meta: { title: '用户', icon: 'auth', noCache: true },
    children: [
      {
        path: 'uses',
        name: 'uses',
        component: resolve => require(['@/views/users/index'], resolve),
        meta: { title: '用户管理', icon: 'user_auth', noCache: true }
      }
    ]
  },
  {
    path: '/groupbuy',
    component: Layout,
    redirect: '/groupbuy/index',
    meta: { title: '预定管理', icon: 'auth', noCache: true },
    children: [
      {
        path: 'groupbuy_index',
        name: 'groupbuy_index',
        component: resolve => require(['@/views/groupbuy/index'], resolve),
        meta: { title: '商品管理', icon: 'user_auth', noCache: true }
      },
      {
        path: 'group_edit',
        name: 'group_edit',
        component: resolve => require(['@/views/groupbuy/edit'], resolve),
        meta: { title: '编辑', icon: 'user_auth', noCache: true, hide: false }
      },
      {
        path: 'groupbuy_wait',
        name: 'groupbuy_wait',
        component: resolve => require(['@/views/groupbuy/wait'], resolve),
        meta: { title: '待发货', icon: 'user_auth', noCache: true }
      },
      {
        path: 'groupbuy_ship',
        name: 'groupbuy_ship',
        component: resolve => require(['@/views/groupbuy/ship'], resolve),
        meta: { title: '已发货', icon: 'user_auth', noCache: true }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    meta: { title: '订单管理', icon: 'auth', noCache: true },
    children: [
      {
        path: 'order_index',
        name: 'order_index',
        component: resolve => require(['@/views/order/index'], resolve),
        meta: { title: '退款申请', icon: 'user_auth', noCache: true }
      },
      {
        path: 'order_trans',
        name: 'order_trans',
        component: resolve => require(['@/views/order/trans'], resolve),
        meta: { title: '提现申请', icon: 'user_auth', noCache: true }
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: '/shop/index',
    meta: { title: '商户管理', icon: 'auth', noCache: true },
    children: [
      {
        path: 'shop_index',
        name: 'shop_index',
        component: resolve => require(['@/views/shop/index'], resolve),
        meta: { title: '商户申请', icon: 'user_auth', noCache: true }
      },
      {
        path: 'shop_goods',
        name: 'shop_goods',
        component: resolve => require(['@/views/shop/goods'], resolve),
        meta: { title: '商品申请', icon: 'user_auth', noCache: true }
      }
    ]
  },
  /* {
    path: '/examine',
    component: Layout,
    redirect: '/examine/index',
    meta: { title: '认证审核', icon: 'auth', noCache: true },
    children: [
      {
        path: 'personal_examine',
        name: 'personal_examine',
        component: resolve => require(['@/views/examine/index'], resolve),
        meta: { title: '个人认证', icon: 'user_auth', noCache: true }
      },
      {
        path: 'company_examine',
        name: 'company_examine',
        component: resolve => require(['@/views/examine/company'], resolve),
        meta: { title: '企业认证', icon: 'user_auth', noCache: true }
      }
    ]
  }, */
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/index',
    meta: { title: '活动审核', icon: 'auth', noCache: true },
    children: [
      {
        path: 'column',
        name: 'column',
        component: resolve => require(['@/views/activity/index'], resolve),
        meta: { title: '栏目活动', icon: 'user_auth', noCache: true }
      },
      {
        path: 'discount',
        name: 'discount',
        component: resolve => require(['@/views/activity/discount'], resolve),
        meta: { title: '特惠活动', icon: 'user_auth', noCache: true }
      },
      {
        path: 'news',
        name: 'news',
        component: resolve => require(['@/views/activity/news'], resolve),
        meta: { title: '快讯活动', icon: 'user_auth', noCache: true }
      },
      {
        path: 'dream',
        name: 'dream',
        component: resolve => require(['@/views/activity/dream'], resolve),
        meta: { title: '梦想加', icon: 'user_auth', noCache: true }
      }
    ]
  },
  {
    path: '/acmanger',
    component: Layout,
    redirect: '/acmanger/index',
    meta: { title: '活动管理', icon: 'auth', noCache: true },
    children: [
      {
        path: 'accolumn',
        name: 'accolumn',
        component: resolve => require(['@/views/acmanger/index'], resolve),
        meta: { title: '栏目活动', icon: 'user_auth', noCache: true }
      },
      {
        path: 'acdiscount',
        name: 'acdiscount',
        component: resolve => require(['@/views/acmanger/discount'], resolve),
        meta: { title: '特惠活动', icon: 'user_auth', noCache: true }
      },
      {
        path: 'acnews',
        name: 'acnews',
        component: resolve => require(['@/views/acmanger/news'], resolve),
        meta: { title: '快讯活动', icon: 'user_auth', noCache: true }
      },
      {
        path: 'acdream',
        name: 'acdream',
        component: resolve => require(['@/views/acmanger/dream'], resolve),
        meta: { title: '梦想加', icon: 'user_auth', noCache: true }
      }
    ]
  },
  {
    path: '/dream_comment',
    component: Layout,
    redirect: '/dream_comment/comment',
    meta: { title: 'comment', icon: 'auth', noCache: true },
    children: [
      {
        path: 'comment',
        name: 'comment',
        component: resolve => require(['@/views/dream_comment/index'], resolve),
        meta: { title: '梦想加评论', icon: 'user_auth', noCache: true }
      }
    ]
  },
  {
    path: '/advert',
    component: Layout,
    redirect: '/clolmun/users',
    meta: { title: '用户', icon: 'auth', noCache: true },
    children: [
      {
        path: 'advert',
        name: 'advert',
        component: resolve => require(['@/views/advert/index'], resolve),
        meta: { title: '广告位管理', icon: 'user_auth', noCache: true }
      }
    ]
  },
  /* {
    path: '/push',
    component: Layout,
    redirect: '/push/index',
    meta: { title: '推送', icon: 'auth', noCache: true },
    children: [
      {
        path: 'index',
        name: 'index',
        component: resolve => require(['@/views/push/index'], resolve),
        meta: { title: '推送', icon: 'user_auth', noCache: true }
      }
    ]
  }, */
  {
    path: '/app',
    component: Layout,
    redirect: '/app/update',
    meta: { title: 'APP', icon: 'auth', noCache: true },
    children: [
      {
        path: 'update',
        name: 'update',
        component: resolve => require(['@/views/app/update'], resolve),
        meta: { title: '更新', icon: 'user_auth', noCache: true }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: false }
]
